package cn.wolfcode.trip.base.util;


import cn.wolfcode.trip.base.domain.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;

public abstract class UserContext {
    public static final String User_IN_SESSION = "User_IN_SESSION";

    public static HttpSession getSession(){
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();
    }

    public static void setUserAttribute(User user){
        getSession().setAttribute("User_IN_SESSION",user);
    }

    public static User getUserAttribute(){
        return (User) getSession().getAttribute(User_IN_SESSION);
    }



}
